﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Marmat.Forms.Design
{
    public class DefaultFilterPanelMatchControlService : IFilterPanelMatchControlService
    {
        Type[] IFilterPanelMatchControlService.GetCollection()
        {
            List<Type> result = new List<Type>();
            result.Add(typeof(TextBox));
            result.Add(typeof(ComboBox));
            result.Add(typeof(NumericBox));
            result.Add(typeof(DateTimePicker));
            result.Add(typeof(LookUpEdit));
            result.Add(typeof(CheckBox));
            result.Add(typeof(DropDownBox));
            return result.ToArray();
        }

        Type IFilterPanelMatchControlService.Match(SmartMatchControlInfo info)
        {
            if (info.PropertyType == typeof(DateTime))
            {
                return typeof(DateTimePicker);
            }
            else if (info.PropertyType == typeof(int) || info.PropertyType == typeof(long) || info.PropertyType == typeof(float) || info.PropertyType == typeof(double) || info.PropertyType == typeof(decimal))
            {
                return typeof(NumericBox);
            }
            else if (info.PropertyType == typeof(bool))
            {
                return typeof(CheckBox);
            }
            else if (info.PropertyType == typeof(string))
            {
                if (Regex.IsMatch(info.PropertyName, "^.*[等级,类别,类型,学历,单位]$|^[部门,岗位].*$"))
                {
                    return typeof(ComboBox);
                }
                else
                {
                    return typeof(TextBox);
                }
            }
            else
            {
                return typeof(TextBox);
            }
        }
    }
}
